package com.design.command.logger;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

// 文本编辑器类
class TextEditor {
    private StringBuilder content = new StringBuilder();
    private List<String> log = new ArrayList<>();

    public void insertText(String text) {
        content.append(text);
        log.add("Inserted: " + text);
    }

    public void deleteText(String text) {
        int index = content.indexOf(text);
        if (index != -1) {
            content.delete(index, index + text.length());
            log.add("Deleted: " + text);
        }
    }

    public void saveLogToFile(String filename) throws IOException {
        try (FileWriter writer = new FileWriter(filename)) {
            for (String entry : log) {
                writer.write(entry + "\n");
            }
        }
    }
}
